<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="系统订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入系统订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column label="系统订单号" align="center" prop="orderNo" />
      <el-table-column label="微信订单号" align="center" prop="transactionId" />
      <el-table-column label="商品名称" align="center" prop="goodsId" >
        <template slot-scope="scope">
          <span>{{scope.row.goods.name}}</span>
        </template>
      </el-table-column>
      <el-table-column label="下单用户" align="center" prop="userId" >
        <template slot-scope="scope">
          <span>{{scope.row.easyUser.nickName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单金额" align="center" prop="money" >
        <template slot-scope="scope">
          <span>{{(scope.row.money)/100}}</span>
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="center" prop="payMoney" >
        <template slot-scope="scope">
          <span>{{(scope.row.payMoney)/100}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createAt"/>
      <el-table-column label="订单状态" align="center" prop="status" >
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.status=='Cancel'">取消支付</el-tag>
          <el-tag type="success" v-if="scope.row.status=='Paid'">已支付</el-tag>
          <el-tag type="warning" v-if="scope.row.status=='None'">待支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payAt"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOrder} from "@/api/debao/goodsOrder";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品订单表格数据
      orderList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        transactionId: null,
        goodsId: null,
        userId: null,
        money: null,
        payMoney: null,
        createAt: null,
        updAt: null,
        status: null,
        payAt: null,
        updateAt: null,
        addressId: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        transactionId: null,
        goodsId: null,
        userId: null,
        money: null,
        payMoney: null,
        createAt: null,
        updAt: null,
        status: null,
        payAt: null,
        updateAt: null,
        addressId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  }
};
</script>
